import { createRouter, createWebHashHistory } from 'vue-router';
import routerGuards from './router-guards';

const routes = [
  {
    path: '/',
    name: 'root',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '',
        name: '首页',
        component: () => import('@/views/index.vue'),
      },
    ],
    meta: {
      title: '合创车联网',
    },
  },
  {
    path: '/login',
    name: '登录',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '合创车联网',
    },
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/components/error-page/404.vue'),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

routerGuards(router);

export default router;
